package com.ksd.oauth2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.ksd.member.Member;

/** 
* 
* @author zbb: 
* @version 2017年9月14日
* 
*/
@Service
public class CustomUserDetailsService implements UserDetailsService  {
	
	@Autowired
	private UserService userService ;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		Member user = userService.findByAccount(username);
		if (user == null) {
			throw new UsernameNotFoundException(String.format("User %s does not exist!", username));
		}
		UserDetails userDetails = new CustomUserDetails(user);
		return userDetails;
	}

}
